package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.OrderDetail;
import com.itheima.reggie.entity.Report;
import com.itheima.reggie.service.OrderDetailService;
import com.itheima.reggie.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/report")
public class ReportController {
//    @Autowired
//    private OrderDetailService orderDetailService;
    @Autowired
    private ReportService reportService;

    @GetMapping("/dish")
    public R<List<Report>> getReport(){
        List<Report> reportList=reportService.getReport();

/*
        List<Report> reportList = new ArrayList<>();
        List<OrderDetail> list=orderDetailService.list();
        for (OrderDetail orderDetail : list) {
            boolean flag = true;
            for (Report report : reportList) {
                if (report.getName().equals(orderDetail.getName())){
                    //如果存在 则在原有基础上添加
                    report.setValue(report.getValue()+orderDetail.getNumber());
                    flag = false;
                    break;
                }
            }
            if(flag){
                //不存在创建新的报表数据
                Report report = new Report();
                report.setName(orderDetail.getName());
                report.setValue(orderDetail.getNumber());
                reportList.add(report);
            }
        }
*/

        return R.success(reportList);
    }



}
